/*****************************************************************************
*Purpose: Estimate core results for Adult Gautreaux Participants 
******************************************************************************/ 

global fe "intakeyear yrbirth  mitrct80"
global notractfe "intakeyear yrbirth  "
global controls "female headage married auto license work emp inc chicago ph i.bed"


global outlist "avgearn3842 avgearn4347 avgearn4852  cumul_earn42  cumul_earn47  cumul_earn52"


capture frame drop lehdadults
frame create lehdadults str35 outcome str35 group str35 spec beta se obs piks treatpiks controlpiks r2

foreach gr in all  {
foreach spec in base nocont notractfe meansd { 
foreach out in $outlist {

	if "`spec'"=="base" {
	reghdfe `out' generalarea $controls if   estsample==1 & `gr'==1, absorb( $fe ) cluster(hhid)
	gen samp_`out'_`gr'=e(sample)
		
	unique pik if e(sample)==1
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1
	local treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0
	local controlpik `=r(sum)'
	frame post lehdadults ("`out'") ("`gr'") ("`spec'") (_b[generalarea]) (_se[generalarea]) (e(N)) (`allpik') (`treatpik') (`controlpik') (e(r2))
	}
	
	if "`spec'"=="nocont" {
	reghdfe `out' generalarea  if  samp_`out'_`gr'==1 & `gr'==1, absorb( $fe ) cluster(hhid)
	unique pik if e(sample)==1
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1
	local treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0
	local controlpik `=r(sum)'
	frame post lehdadults ("`out'") ("`gr'") ("`spec'") (_b[generalarea]) (_se[generalarea]) (e(N)) (`allpik') (`treatpik') (`controlpik') (e(r2))
			
	}
	
	if "`spec'"=="notractfe" {
	reghdfe `out' generalarea $controls if  samp_`out'_`gr'==1 & `gr'==1, absorb( $notractfe ) cluster(hhid)
	unique pik if e(sample)==1
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1
	local treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0
	local controlpik `=r(sum)'
	frame post lehdadults ("`out'") ("`gr'") ("`spec'") (_b[generalarea]) (_se[generalarea]) (e(N)) (`allpik') (`treatpik') (`controlpik') (e(r2))
			
	}
	
	if "`spec'"=="meansd" {
	sum `out' if generalarea!=1 & samp_`out'_`gr'==1 & `gr'==1
	local controlmean `=r(mean)'
	local controlsd `=r(sd)'
	unique pik if generalarea!=1 & samp_`out'_`gr'==1 
	frame post lehdadults ("`out'") ("`gr'") ("`spec'") (`controlmean') (`controlsd') (r(sum)) (r(sum)) (r(sum)) (r(sum)) (r(sum))
			
	}

	
	}
}
}
frame lehdadults: save "${output}/adults_lehd_results.dta", replace
frame lehdadults: export delimited using "${output}/adults_lehd_prestatecounts_results.csv", replace


*************************
****** Census 2010 ******
*************************

global cenout "married_2010 married_white owner_2010"  

capture frame drop hohcen10
frame create hohcen10 str35 outcome str35 group str35 spec beta se obs piks dv1treatpiks dv1controlpiks dv0treatpiks dv0controlpiks

foreach gr in all  {
foreach spec in base nocont notractfe meansd { 
foreach cout in $cenout {

	if "`spec'"=="base" {
	reghdfe `cout' generalarea $controls if  estsample==1 & `gr'==1, absorb( $fe ) cluster(hhid)
	gen samp_`cout'_`gr'=e(sample) 	
	unique pik if e(sample)==1
	
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `cout'==1
	local y1treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `cout'==1
	local y1controlpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `cout'==0
	local y0treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `cout'==0
	local y0controlpik `=r(sum)'
	
	
	frame post hohcen10 ("`cout'") ("`gr'") ("`spec'") (_b[generalarea]) (_se[generalarea]) (e(N)) (`allpik') (`y1treatpik') (`y1controlpik') (`y0treatpik') (`y0controlpik')
	}
	
	if "`spec'"=="nocont" {
	reghdfe `cout' generalarea  if  samp_`cout'_`gr'==1 & `gr'==1, absorb( $fe ) cluster(hhid)
	unique pik if e(sample)==1
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `cout'==1
	local y1treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `cout'==1
	local y1controlpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `cout'==0
	local y0treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `cout'==0
	local y0controlpik `=r(sum)'
	
	
	frame post hohcen10 ("`cout'") ("`gr'") ("`spec'") (_b[generalarea]) (_se[generalarea]) (e(N)) (`allpik') (`y1treatpik') (`y1controlpik') (`y0treatpik') (`y0controlpik')
			
	}
	
	if "`spec'"=="notractfe" {
	reghdfe `cout' generalarea $controls if  samp_`cout'_`gr'==1 & `gr'==1, absorb( $notractfe ) cluster(hhid)
	unique pik if e(sample)==1
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `cout'==1
	local y1treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `cout'==1
	local y1controlpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `cout'==0
	local y0treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `cout'==0
	local y0controlpik `=r(sum)'
	
	
	frame post hohcen10 ("`cout'") ("`gr'") ("`spec'") (_b[generalarea]) (_se[generalarea]) (e(N)) (`allpik') (`y1treatpik') (`y1controlpik') (`y0treatpik') (`y0controlpik')
			
	}
	
	if "`spec'"=="meansd" {
	sum `cout' if generalarea!=1 & `cout'!=. & `gr'==1
	local controlmean `=r(mean)'
	local controlsd `=r(sd)'
	
	unique pik if generalarea!=1 & `cout'!=. 	
	frame post hohcen10 ("`cout'") ("`gr'") ("`spec'") (`controlmean') (`controlsd') (r(sum)) (r(sum)) (r(sum)) (r(sum)) (r(sum))  (r(sum)) 
			
	}

	
	}
}
}
frame hohcen10: save "${output}/adults_cen10_results.dta", replace
frame hohcen10: export delimited using "${output}/adults_cen10_results.csv", replace

*************************
***** Census 2000 *******
*************************

global cenout "c2000_shblack c2000_shwhite c2000_povrate"  

capture frame drop hohcen00
frame create hohcen00 str35 outcome str35 group str35 spec beta se obs piks treatpiks controlpiks

foreach gr in all  {
foreach spec in base nocont notractfe meansd { 
foreach cout in $cenout {

	if "`spec'"=="base" {
	reghdfe `cout' generalarea $controls if  estsample==1 & `gr'==1, absorb( $fe ) cluster(hhid)
	gen samp_`cout'_`gr'=e(sample) 	
	unique pik if e(sample)==1
	
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 
	local treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 
	local controlpik `=r(sum)'
	
	
	frame post hohcen00 ("`cout'") ("`gr'") ("`spec'") (_b[generalarea]) (_se[generalarea]) (e(N)) (`allpik') (`treatpik') (`controlpik')  
	}
	
	if "`spec'"=="nocont" {
	reghdfe `cout' generalarea  if  samp_`cout'_`gr'==1 & `gr'==1, absorb( $fe ) cluster(hhid)
	unique pik if e(sample)==1
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1  
	local treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 
	local controlpik `=r(sum)'
	
	frame post hohcen00 ("`cout'") ("`gr'") ("`spec'") (_b[generalarea]) (_se[generalarea]) (e(N)) (`allpik') (`treatpik') (`controlpik') 
	
	}
	
	if "`spec'"=="notractfe" {
	reghdfe `cout' generalarea $controls if  samp_`cout'_`gr'==1 & `gr'==1, absorb( $notractfe ) cluster(hhid)
	unique pik if e(sample)==1
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1  
	local treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0  
	local controlpik `=r(sum)'
	
	
	frame post hohcen00 ("`cout'") ("`gr'") ("`spec'") (_b[generalarea]) (_se[generalarea]) (e(N)) (`allpik') (`treatpik') (`controlpik') 
			
	}
	
	if "`spec'"=="meansd" {
	sum `cout' if generalarea!=1 & `cout'!=. & `gr'==1
	local controlmean `=r(mean)'
	local controlsd `=r(sd)'
	
	unique pik if generalarea!=1 & `cout'!=. 	
	frame post hohcen00 ("`cout'") ("`gr'") ("`spec'") (`controlmean') (`controlsd') (r(sum)) (r(sum)) (r(sum)) (r(sum))  
			
	}

	
	}
}
}
frame hohcen00: save "${output}/adults_cen00_results.dta", replace
frame hohcen00: export delimited using "${output}/adults_cen00_results.csv", replace

*************************
****** MAFARF 2019 ******
*************************

global moutlist "m2019_pctblack m2019_pctwhite m2019_povrate own20102012 own20172019"


capture frame drop marf
frame create marf str35 outcome str35 group str35 spec beta se obs piks treatpiks controlpiks dv1treatpiks dv1controlpiks dv0treatpiks dv0controlpiks 

foreach gr in all  {
foreach spec in base nocont notractfe meansd { 
foreach mout in $moutlist {

	if "`spec'"=="base" {
	reghdfe `mout' generalarea $controls if  estsample==1 & `gr'==1, absorb( $fe ) cluster(hhid)
	gen samp_`mout'_`gr'=e(sample) 	
	unique pik if e(sample)==1
	

	if "`mout'"!="own20102012 " & "`mout'"!="own20172019"  {
	unique pik if e(sample)==1
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1
	local treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 
	local controlpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1  
	local y1treatpik `=-99999'
	unique pik if e(sample)==1 & generalarea==0  
	local y1controlpik `=-99999'
	unique pik if e(sample)==1 & generalarea==1 
	local y0treatpik `=-99999'
	unique pik if e(sample)==1 & generalarea==0 
	local y0controlpik `=-99999'
	
	}

	
	if "`mout'"=="own20102012" | "`mout'"=="own20172019" {
	unique pik if e(sample)==1	
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1
	local treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 
	local controlpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `mout'==1
	local y1treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `mout'==1
	local y1controlpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `mout'==0
	local y0treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `mout'==0
	local y0controlpik `=r(sum)'
	}
	
	frame post marf ("`mout'") ("`gr'") ("`spec'") (_b[generalarea]) (_se[generalarea]) (e(N)) (`allpik') (`treatpik') (`controlpik') (`y1treatpik') (`y1controlpik') (`y0treatpik') (`y0controlpik') 
	}
	
	if "`spec'"=="nocont" {
	reghdfe `mout' generalarea  if  samp_`mout'_`gr'==1 & `gr'==1, absorb( $fe ) cluster(hhid)

	if "`mout'"!="own20102012 " & "`mout'"!="own20172019"  {
	unique pik if e(sample)==1
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1
	local treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 
	local controlpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1  
	local y1treatpik `=-99999'
	unique pik if e(sample)==1 & generalarea==0  
	local y1controlpik `=-99999'
	unique pik if e(sample)==1 & generalarea==1 
	local y0treatpik `=-99999'
	unique pik if e(sample)==1 & generalarea==0 
	local y0controlpik `=-99999'
	
	}

	
	if "`mout'"=="own20102012" | "`mout'"=="own20172019" {
	unique pik if e(sample)==1	
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1
	local treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 
	local controlpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `mout'==1
	local y1treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `mout'==1
	local y1controlpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `mout'==0
	local y0treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `mout'==0
	local y0controlpik `=r(sum)'
	}
		
	
	frame post marf ("`mout'") ("`gr'") ("`spec'") (_b[generalarea]) (_se[generalarea]) (e(N)) (`allpik') (`treatpik') (`controlpik')  (`y1treatpik') (`y1controlpik') (`y0treatpik') (`y0controlpik')  
			
	}
	
	if "`spec'"=="notractfe" {
	reghdfe `mout' generalarea $controls if  samp_`mout'_`gr'==1 & `gr'==1, absorb( $notractfe ) cluster(hhid)

	if "`mout'"!="own20102012 " & "`mout'"!="own20172019"  {
	unique pik if e(sample)==1
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1
	local treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 
	local controlpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1  
	local y1treatpik `=-99999'
	unique pik if e(sample)==1 & generalarea==0  
	local y1controlpik `=-99999'
	unique pik if e(sample)==1 & generalarea==1 
	local y0treatpik `=-99999'
	unique pik if e(sample)==1 & generalarea==0 
	local y0controlpik `=-99999'
	
	}

	
	if "`mout'"=="own20102012" | "`mout'"=="own20172019" {
	unique pik if e(sample)==1	
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1
	local treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 
	local controlpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `mout'==1
	local y1treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `mout'==1
	local y1controlpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `mout'==0
	local y0treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `mout'==0
	local y0controlpik `=r(sum)'
	}
		

	
	frame post marf ("`mout'") ("`gr'") ("`spec'") (_b[generalarea]) (_se[generalarea]) (e(N)) (`allpik') (`treatpik') (`controlpik')  (`y1treatpik') (`y1controlpik') (`y0treatpik') (`y0controlpik')  
			
	}
	
	if "`spec'"=="meansd" {
	sum `mout' if generalarea!=1 & `mout'!=. & `gr'==1
	local controlmean `=r(mean)'
	local controlsd `=r(sd)'
	
	unique pik if generalarea!=1 & `mout'!=. 	
	frame post marf ("`mout'") ("`gr'") ("`spec'") (`controlmean') (`controlsd') (r(sum)) (r(sum)) (-99999) (-99999)  (-99999) (-99999) (-99999)  (-99999) 
			
	}

	
	}
}
}
			

frame marf: save "${output}/adults_mafarf_results.dta", replace
frame marf: export delimited using "${output}/adults_mafarf_results.csv", replace




*******************************
***** Mortality Numident ******
*******************************


global numiout "died died_precovid diedlt70 diedlt60 diedlt50"  

capture frame drop hohnumi
frame create hohnumi str35 outcome str35 group str35 spec beta se obs piks treatpiks controlpiks

foreach gr in all  {
foreach spec in base nocont notractfe meansd { 
foreach cout in $numiout {

	if "`spec'"=="base" {
	reghdfe `cout' generalarea $controls if  estsample==1 & `gr'==1 & agein2019>=57, absorb( $fe ) cluster(hhid)
	gen samp_`cout'_`gr'=e(sample) 	
	unique pik if e(sample)==1
	
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 
	local treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 
	local controlpik `=r(sum)'
	
	
	frame post hohnumi ("`cout'") ("`gr'") ("`spec'") (_b[generalarea]) (_se[generalarea]) (e(N)) (`allpik') (`treatpik') (`controlpik')  
	}
	
	if "`spec'"=="nocont" {
	reghdfe `cout' generalarea  if  samp_`cout'_`gr'==1 & `gr'==1, absorb( $fe ) cluster(hhid)
	unique pik if e(sample)==1
	local allpik `=r(sum)'
	summ yrbirth ageatintake  if e(sample)==1, d
	histogram ageatintake, discrete
	unique pik if e(sample)==1 & generalarea==1  
	local treatpik `=r(sum)'
	summ yrbirth ageatintake if e(sample)==1 & generalarea==1, d
	unique pik if e(sample)==1 & generalarea==0 
	local controlpik `=r(sum)'
	summ yrbirth ageatintake if e(sample)==1 & generalarea==0, d
	
	frame post hohnumi ("`cout'") ("`gr'") ("`spec'") (_b[generalarea]) (_se[generalarea]) (e(N)) (`allpik') (`treatpik') (`controlpik') 
	
	}
	
	if "`spec'"=="notractfe" {
	reghdfe `cout' generalarea $controls if  samp_`cout'_`gr'==1 & `gr'==1, absorb( $notractfe ) cluster(hhid)
	unique pik if e(sample)==1
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1  
	local treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0  
	local controlpik `=r(sum)'
	
	
	frame post hohnumi ("`cout'") ("`gr'") ("`spec'") (_b[generalarea]) (_se[generalarea]) (e(N)) (`allpik') (`treatpik') (`controlpik') 
			
	}
	
	if "`spec'"=="meansd" {
	sum `cout' if generalarea!=1 & `cout'!=. & `gr'==1
	local controlmean `=r(mean)'
	local controlsd `=r(sd)'
	
	unique pik if generalarea!=1 & `cout'!=. 	
	frame post hohnumi ("`cout'") ("`gr'") ("`spec'") (`controlmean') (`controlsd') (r(sum)) (r(sum)) (r(sum)) (r(sum))  
			
	}

	
	}
}
}
frame hohnumi: save "${output}/adults_numi_results.dta", replace
frame hohnumi: export delimited using "${output}/adults_numi_results.csv", replace


 
